<?php !defined( 'SUNCMS' ) && exit( 'No direct script access allowed'  );

/**
 * 
 * Sun CMS
 * 
 * @author			Burning
 * @copyright		Copyright (c) 2009, IsunCms.Com.
 * @license			http://www.isuncms.com/license.htm
 * @link				http://www.isuncms.com/
 * @since				Version 1.0 Beta
 * 
 */

class Images{

	var $image_lib;
	
	function __construct()
	{
		include( SUNCMS.'include/librarys/image_lib.class.php' );
		$this->image_lib = new Image_lib();
	}
	
	function resize_images( $file, $width, $height, $new_img_path = 'thumb' )
	{
		$new_image_path = SUNCMS.'uploads/'.$new_img_path;
		!is_dir( $new_image_path ) && create_dir( $new_image_path );
		$this->image_lib->clear();
		$imgconfig['image_library'] 	= 'gd';
		$imgconfig['source_image'] 		= SUNCMS.'uploads/temp/'.$file;
		$imgconfig['new_image'] 		= $new_image_path.'/'.$file;
		$imgconfig['master_dim'] 		= 'width';
		$imgconfig['width'] 			= $width;
		$imgconfig['height'] 			= $height;
		$this->image_lib->initialize( $imgconfig );
		$res = $this->image_lib->resize();
		@unlink( SUNCMS.'uploads/temp/'.$file );
		return ( $res )?true:false;
	}
	
	function watermark_word( $file, $word, $source_img_path = 'temp', $new_img_path = 'images' )
	{
		$new_image_path = SUNCMS.'uploads/'.$new_img_path;
		!is_dir( $new_image_path ) && create_dir( $new_image_path );
		$this->image_lib->clear();
		$imgconfig['image_library'] = 'gd';
		$imgconfig['source_image'] = SUNCMS.'uploads/'.$source_img_path.'/'.$file;
		$imgconfig['wm_text'] = $word;
		$imgconfig['wm_type'] = 'text';
		$imgconfig['wm_font_path'] = SUN_FONT.'/arialni.ttf';
		$imgconfig['wm_font_size'] = '14';
		$imgconfig['wm_font_color'] = '00CCFF';
		$imgconfig['wm_vrt_alignment'] = 'bottom';
		$imgconfig['wm_hor_alignment'] = 'right';
		$imgconfig['new_image'] = $new_image_path.'/'.$file;
		$this->image_lib->initialize( $imgconfig );
		$res = $this->image_lib->watermark();
		@unlink( SUNCMS.'uploads/'.$source_img_path.'/'.$file );
		return ( $res )?true:false;
	}
	
	function watermark_img( $file, $img, $source_img_path = 'temp', $new_img_path = 'images' )
	{
		$new_image_path = SUNCMS.'uploads/'.$new_img_path;
		!is_dir( $new_image_path ) && create_dir( $new_image_path );
		$this->image_lib->clear();
		$imgconfig['image_library'] = 'gd';
		$imgconfig['source_image'] = SUNCMS.'uploads/temp/'.$file;
		$imgconfig['wm_overlay_path'] = SUNCMS.'uploads/watermark/'.$img;
		$imgconfig['wm_type'] = 'overlay';
		$imgconfig['wm_vrt_alignment'] = 'bottom';
		$imgconfig['wm_hor_alignment'] = 'right';
		$imgconfig['new_image'] = $new_image_path.'/'.$file;
		$this->image_lib->initialize( $imgconfig );
		$res = $this->image_lib->watermark();
		@unlink( SUNCMS.'uploads/'.$source_img_path.'/'.$file );
		return ( $res )?true:false;
	}
	
}